package org.glut.wechat.chat.config;

import jakarta.servlet.http.HttpSession;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.server.HandshakeRequest;
import jakarta.websocket.server.ServerEndpointConfig;

import java.util.Collections;

/**
 * 用于获取HttpSession对象
 */
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {

        // 将 HandshakeRequest 存入配置的用户属性，供 ChatEndpoint 使用
        sec.getUserProperties().put(HandshakeRequest.class.getName(), request);

        //获取Httpsession对象
        HttpSession httpSession = (HttpSession) request.getHttpSession();

        //将Httpsession对象存储到配置对象中
        if(httpSession!=null){
        sec.getUserProperties().put(HttpSession.class.getName(), httpSession);}

    }

}
